// 支持 f32/f64 的范数计算
pub fn optimized_norm<I>(iter: I) -> f32
where
    I: Iterator<Item = f32>,
{
    let (sum, _) = iter.fold(
        (0.0_f32, 0.0_f32),
        |(sum, comp), x| {
            let x_sq = x * x;
            let y = x_sq - comp;
            let t = sum + y;
            let next_comp = (t - sum) - y;
            (t, next_comp)
        },
    );

    if sum == 0.0 {
        0.0
    } else {
        sum.sqrt()
    }
}

// f64 版本（可通过宏简化）
pub fn optimized_norm_f64<I>(iter: I) -> f64
where
    I: Iterator<Item = f64>,
{
    let (sum, _) = iter.fold(
        (0.0_f64, 0.0_f64),
        |(sum, comp), x| {
            let x_sq = x * x;
            let y = x_sq - comp;
            let t = sum + y;
            let next_comp = (t - sum) - y;
            (t, next_comp)
        },
    );

    if sum == 0.0 {
        0.0
    } else {
        sum.sqrt()
    }
}